import 'package:family_app/src/features/gallery/models/photo_model.dart';

/// 照片分组模型，按日期分组
class PhotoGroupModel {
  /// 日期（分组标识）
  final DateTime date;
  
  /// 该日期下的照片列表
  final List<PhotoModel> photos;
  
  /// 构造函数
  PhotoGroupModel({
    required this.date,
    required this.photos,
  });
  
  /// 从接口返回的JSON数据创建对象
  factory PhotoGroupModel.fromJson(Map<String, dynamic> json) {
    // 解析日期
    final date = DateTime.parse(json['date'] as String);
    
    // 解析照片列表
    final List<dynamic> photoList = json['list'] as List<dynamic>;
    final photos = photoList.map((photoJson) {
      return PhotoModel(
        id: photoJson['id'].toString(),
        albumId: photoJson['albumId'].toString(),
        url: photoJson['photoUrl'],
        name: photoJson['photoName'],
        createdAt: DateTime.parse(photoJson['createAt']),
        updatedAt: DateTime.parse(photoJson['updateAt']),
      );
    }).toList();
    
    return PhotoGroupModel(
      date: date,
      photos: photos,
    );
  }
}
